package com.coder.ipc.aidl

import android.app.Service
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import android.util.Log

/**
 * 服务端代码，提供计算
 *
 * @author yuhushuan
 * @date 2020/12/13 20:32
 */
class ICalculateService : Service() {
    private val tag = "Calculate"

    private val mBinder = object : ICalculate.Stub() {
        override fun basicTypes(anInt: Int, aLong: Long, aBoolean: Boolean, aFloat: Float, aDouble: Double, aString: String?) {
            Log.i(tag, "basicTypes-anInt:$anInt, aLong:$aLong, aBoolean:$aBoolean, aFloat:$aFloat, aDouble:$aDouble, aString:$aString")
        }

        override fun add(first: Int, second: Int): Int {
            Log.d(tag, "add() first:$first, second:$second")
            return first + second
        }

    }

    override fun onBind(intent: Intent?): IBinder? {
        Log.d(tag, "onBind()-intent:$intent")
        return mBinder
    }

    override fun unbindService(conn: ServiceConnection) {
        super.unbindService(conn)
        Log.d(tag, "unbindService()-conn:$conn")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(tag, "onDestroy()")
    }

    override fun onUnbind(intent: Intent?): Boolean {
        return super.onUnbind(intent)
        Log.d(tag, "onUnbind()-intent:$intent")
    }

}